<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>JOB日志清理</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
</head>
<body>
<!-- 你的HTML代码 -->
<div class="demoTable" style="padding: 5px">

    <form class="layui-form">

        <div class="layui-inline">
            <label class="layui-form-label">执行状态</label>
            <div class="layui-input-block">
                <select name="state">
                    <option value="">--请选择--</option>
                    <option value="NORMAL">正常</option>
                    <option value="RUN"  >运行</option>
                    <option value="ERROR"  >异常</option>
                </select>
            </div>
        </div>
        <button class="layui-btn layui-btn-primary" lay-submit lay-filter="clearLog"  >清理日志</button>
        <button class="layui-btn layui-btn-primary" lay-submit lay-filter="reload"  >搜索</button>

    </form>
    <hr>
    <table class="layui-hide" id="LAY_table_user" lay-filter="LAY_table_user"></table>
</div>


<script src="../layui/layui.all.js"></script>
<script>

    var search = window.location.search ;

    var tableOption =  {
                elem: '#LAY_table_user'
                ,url:"../xxdsqljob/jobLogList"+search
                ,cols: [[
                     {field:'jobId', title: 'ID', width:120, sort: true }
                    ,{field:'jobName', title: '名称', width:180,sort: true}
                    ,{field:'startTime', title: '开始时间', width:180, sort: true}
                    ,{field:'lastTime', title: '结束时间', width:180, sort: true}
                    ,{field:'period', title: '频率', width:120,templet:function(d){
                        return d.period + " " + d.unit
                    }}
                    ,{field:'state', title: '状态', sort: true, width:100}
                    ,{field:'stateInfo', title: '信息', sort: true }
                    ,{field:'active', title: '有效', sort: true, width:80,templet:function(d){
                        var active  =   '否'
                        if(d.active == "Y"){
                            active =   '是'
                        }
                        return active
                    }}
                    ,{field:'logDated', title: 'LOG时间', width:180, sort: true}
                ]]
                ,id: 'LAY_table_user'
                ,page: true
                ,height: 'full-130'
            }

    //由于模块都一次性加载，因此不用执行 layui.use() 来加载对应模块，直接使用即可：
    ;!function(){
        var layer = layui.layer
        var form = layui.form;
        var table = layui.table;
        var $ = layui.$

        table.render(tableOption)

        form.on("submit(clearLog)",function(obj){
            layer.open({
                title:"清理日志",
                content: $("#clearTypeDom").html()  ,
                type:1,
                success:function(layero, index){
                    form.render('select','clearType-form');
                },
                area: ['30%', '50%']
            });
            return false
        })

        form.on("submit(clearType-bt)",function(obj){
            //console.log(obj.field)
            $.getJSON("../xxdsqljob/deleteLog"+search,obj.field,function(rst){
                if(rst.code!=0){
                    layer.alert(rst.msg)
                }else{
                    layer.close(layer.index)
                    table.render(tableOption)
                }
            })
            return false
        })


        form.on("submit(reload)",function(obj){
            //console.log(obj.field)
            table.reload("LAY_table_user",{
                where:obj.field
            })
            return false
        })

    }();

</script>

</body>

<script type="text/html" id="clearTypeDom">
    <div style="padding: 5px">
        <form  class="layui-form" lay-filter="clearType-form" >

            <div class="layui-form-item">
                <label class="layui-form-label">清理方式</label>
                <div class="layui-input-block">
                    <select name="clearType" lay-filter="clearType">
                        <option value="0">清理所有</option>
                        <option value="30">清理30天以前</option>
                        <option value="7"  >清理7天以前</option>
                        <option value="15">清理15天以前</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="clearType-bt">立即提交</button>
                </div>
            </div>
        </form>
    </div>
</script>

</html>
